// createRouter:创建路由
// createWebHashHistory 哈希路由模式
// createWebHistory     History 模式
import { createRouter, createWebHashHistory } from 'vue-router'
const Layout = () => import('@/views/Layout')
const Home = () => import('@/views/Home')
const category = () => import('@/views/category')
const sub = () => import('@/views/category/sub')
const goods = () => import('@/views/goods')
const login = () => import('@/views/login/index')
const callback = () => import('@/views/login/callback')
const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/',
        component: Home
      },
      // 一级路由
      {
        path: 'category/:id',
        component: category
      },
      // 二级路由
      {
        path: 'category/sub/:id',
        component: sub
      },
      {
        path: 'product/:id',
        component: goods
      }
    ]
  },
  {
    path: '/login',
    component: login
  },
  {
    path: '/login/callback',
    component: callback
  }
]

// vue2 ：new router
// vue3 的写法
const router = createRouter({
  history: createWebHashHistory(),
  routes,
  // 滚动行为
  scrollBehavior: () => {
    // vue2 {x:0,y0}
    // vue3 {top:0,left:0}
    // 每一页从0开始  feefg
    return { top: 0 }
  }
})

export default router
